/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.evl.tecinfo.gui;

import br.com.evl.tecinfo.modelo.Cargo;
import br.com.evl.tecinfo.modelo.Funcionario;
import java.awt.Color;
import java.util.ArrayList;
import javax.swing.JOptionPane;

/**
 *
 * @author Tecinfo
 */
public class CadastroCargo extends javax.swing.JFrame {

    private int clicou_ok;
    private int linha_editar = -1;

    /**
     * Creates new form cadastrarCargo
     */
    public CadastroCargo() {
        initComponents();
        setTitle("Cadastrar Cargo");
        setSize(315, 285);
        setLocationRelativeTo(this);

    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabelCadastrarCargo = new javax.swing.JLabel();
        jlabel_nome_cargo = new javax.swing.JLabel();
        jLabel_numero_cargo = new javax.swing.JLabel();
        jTextFieldnome_cargo = new javax.swing.JTextField();
        jButtoncadastrar_cargo = new javax.swing.JButton();
        jButton_cancelar_cargo = new javax.swing.JButton();
        jSpinnerNumeroCadastroCargo = new javax.swing.JSpinner();
        jLabelIMGCadastrarCargo = new javax.swing.JLabel();
        jLabelIMGBacgroundCC = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setResizable(false);
        getContentPane().setLayout(null);

        jLabelCadastrarCargo.setFont(new java.awt.Font("Century Gothic", 0, 15)); // NOI18N
        jLabelCadastrarCargo.setForeground(new java.awt.Color(102, 102, 102));
        jLabelCadastrarCargo.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabelCadastrarCargo.setText("CADASTRAR CARGO");
        getContentPane().add(jLabelCadastrarCargo);
        jLabelCadastrarCargo.setBounds(60, 20, 180, 40);

        jlabel_nome_cargo.setFont(new java.awt.Font("Century Gothic", 0, 12)); // NOI18N
        jlabel_nome_cargo.setText("Nome:");
        getContentPane().add(jlabel_nome_cargo);
        jlabel_nome_cargo.setBounds(30, 130, 48, 27);

        jLabel_numero_cargo.setFont(new java.awt.Font("Century Gothic", 0, 12)); // NOI18N
        jLabel_numero_cargo.setText("Número:");
        getContentPane().add(jLabel_numero_cargo);
        jLabel_numero_cargo.setBounds(30, 90, 58, 27);

        jTextFieldnome_cargo.setFont(new java.awt.Font("Century Gothic", 0, 15)); // NOI18N
        jTextFieldnome_cargo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextFieldnome_cargoActionPerformed(evt);
            }
        });
        getContentPane().add(jTextFieldnome_cargo);
        jTextFieldnome_cargo.setBounds(90, 130, 190, 30);

        jButtoncadastrar_cargo.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/com/evl/tecinfo/gui/imagens/conformado20x20.png"))); // NOI18N
        jButtoncadastrar_cargo.setText("CADASTRAR");
        jButtoncadastrar_cargo.setToolTipText("");
        jButtoncadastrar_cargo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtoncadastrar_cargoActionPerformed(evt);
            }
        });
        getContentPane().add(jButtoncadastrar_cargo);
        jButtoncadastrar_cargo.setBounds(20, 200, 130, 30);

        jButton_cancelar_cargo.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/com/evl/tecinfo/gui/imagens/sair20x20.png"))); // NOI18N
        jButton_cancelar_cargo.setText("CANCELAR");
        jButton_cancelar_cargo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton_cancelar_cargoActionPerformed(evt);
            }
        });
        getContentPane().add(jButton_cancelar_cargo);
        jButton_cancelar_cargo.setBounds(170, 200, 120, 30);

        jSpinnerNumeroCadastroCargo.setModel(new javax.swing.SpinnerNumberModel(0, 0, 20, 1));
        getContentPane().add(jSpinnerNumeroCadastroCargo);
        jSpinnerNumeroCadastroCargo.setBounds(90, 90, 68, 26);

        jLabelIMGCadastrarCargo.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/com/evl/tecinfo/gui/imagens/CADASTRODEUSUARIO.png"))); // NOI18N
        getContentPane().add(jLabelIMGCadastrarCargo);
        jLabelIMGCadastrarCargo.setBounds(50, 20, 200, 40);

        jLabelIMGBacgroundCC.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/com/evl/tecinfo/gui/imagens/backgroud.jpg"))); // NOI18N
        getContentPane().add(jLabelIMGBacgroundCC);
        jLabelIMGBacgroundCC.setBounds(0, 0, 310, 260);

        pack();
        setLocationRelativeTo(null);
    }// </editor-fold>//GEN-END:initComponents

    private void jTextFieldnome_cargoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextFieldnome_cargoActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jTextFieldnome_cargoActionPerformed

    private void jButtoncadastrar_cargoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtoncadastrar_cargoActionPerformed
        ArrayList <Cargo> cargos = new ArrayList<>();
        Cargo nCargo = new Cargo();
        nCargo.setNumero((int) jSpinnerNumeroCadastroCargo.getValue());
        nCargo.setNome(jTextFieldnome_cargo.getText());
        cargos.add(nCargo);
    
        boolean numerovazio = false;
        boolean nomevazio = false;
        //CÓDIGO PARA CHECAR SE OS CAMPOS DO CADASTROS E ALTERAR COR DOS CAMPOS VAZIOS
        if (linha_editar == -1) {
            if ((int) jSpinnerNumeroCadastroCargo.getValue() == 0) {
                jSpinnerNumeroCadastroCargo.setForeground(new Color(255, 0, 51));
                numerovazio = true;
            } else {
                jSpinnerNumeroCadastroCargo.setForeground(new Color(0, 0, 0));
                numerovazio = false;
            }
            if (jTextFieldnome_cargo.getText().equals("")) {
                jTextFieldnome_cargo.setBackground(new Color(255, 209, 209));
                nomevazio = true;
            } else {
                jTextFieldnome_cargo.setBackground(new Color(255, 255, 255));
                nomevazio = false;
            }
            // CHECANDO SE EXISTE CAMPOS VAZIOS
            if (nomevazio == true || numerovazio == true) {
                java.awt.Toolkit.getDefaultToolkit().beep();
                JOptionPane.showMessageDialog(null, "Exite campos vazios!");
                // CHECANDO SE OS CAMPOS ESTÃO PREENCHIDOS 
            } else if (nomevazio == false && numerovazio == false) {
                //CONFIRMAÇÃO DE CADASTRO
                clicou_ok = JOptionPane.showConfirmDialog(null, "Deseja CADASTRAR o Caogo?", "Confirmação", JOptionPane.YES_NO_OPTION);
                if (clicou_ok == JOptionPane.YES_OPTION) {
                    
                    
                    
                    //CADASTRO CONCLUÍDO ----------                   
                    JOptionPane.showMessageDialog(null, "Cargo cadastrado com sucesso!");                    
                    clicou_ok = JOptionPane.showConfirmDialog(null, "Deseja continuar?", "Confirmação", JOptionPane.YES_NO_OPTION);
                    if (clicou_ok == JOptionPane.YES_OPTION) {
                        jTextFieldnome_cargo.setText("");
                        jSpinnerNumeroCadastroCargo.setValue(0);
                    } else if (clicou_ok == JOptionPane.NO_OPTION) {
                        this.dispose();
                    }
                } else if (clicou_ok == JOptionPane.NO_OPTION) {
                }
            }
        }
    }//GEN-LAST:event_jButtoncadastrar_cargoActionPerformed

    private void jButton_cancelar_cargoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton_cancelar_cargoActionPerformed
        //MENSAGEM DE CONFIMAÇÃO
        clicou_ok = JOptionPane.showConfirmDialog(null, "Deseja cancelar o cadastro do cargo do funcionario?", "Confirmação", JOptionPane.YES_NO_OPTION);
        if (clicou_ok == JOptionPane.YES_OPTION) {
            this.dispose();
        } else if (clicou_ok == JOptionPane.NO_OPTION) {         
        }
    }//GEN-LAST:event_jButton_cancelar_cargoActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(CadastroCargo.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(CadastroCargo.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(CadastroCargo.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(CadastroCargo.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new CadastroCargo().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton_cancelar_cargo;
    private javax.swing.JButton jButtoncadastrar_cargo;
    private javax.swing.JLabel jLabelCadastrarCargo;
    private javax.swing.JLabel jLabelIMGBacgroundCC;
    private javax.swing.JLabel jLabelIMGCadastrarCargo;
    private javax.swing.JLabel jLabel_numero_cargo;
    private javax.swing.JSpinner jSpinnerNumeroCadastroCargo;
    private javax.swing.JTextField jTextFieldnome_cargo;
    private javax.swing.JLabel jlabel_nome_cargo;
    // End of variables declaration//GEN-END:variables
}
